package org.webArchi.common.web.action.login;
/**
 * @author amith jayasekara
 *
 * User login action
 */

import com.opensymphony.xwork2.ActionSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.PrincipalAware;
import org.apache.struts2.interceptor.PrincipalProxy;

import java.util.Map;


public class UserLoginAction extends ActionSupport implements SessionAware, PrincipalAware {
    private static final Logger logger = LoggerFactory.getLogger(UserLoginAction.class);

    private Map session;
    private String userId;
    private String password;


    public UserLoginAction() {
        //Default constructor
    }

    /**
     * Logging user to the system
     *
     * @return success of error
     */
    public String login() {
        try {
            logger.info("Attempt to logging to the system with user name : {} ", userId);
        } catch (Exception e) {
            logger.debug("exception when logging to the system for the user : {} ", userId, e);
            return ActionSupport.ERROR;
        }
        return ActionSupport.SUCCESS;
    }


    /**
     * Log out from the system
     * This function will cleat the user instance from the web session
     *
     * @return success or error
     */
    public String logout() {
        try {
            logger.info("user : {} logout successfully ");
        } catch (Exception e) {
            logger.debug("exception when logout from the current user session: {} ", e);
        }
        return ActionSupport.SUCCESS;
    }

    public void setSession(Map map) {
        this.session = map;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Override
    public void setPrincipalProxy(PrincipalProxy principalProxy) {

    }
}
